<?php

//==========================================
function readCurrentValue($file)
//==========================================
{

  if(!file_exists($file))
    {
      return("-");;
    }

  $in = fopen($file,"r");
  if($in)
    {
      $row = fgets($in);
    }  
  fclose($in);
  return($row);
}

//==========================================
function showFileContent($file)
//==========================================
{
  $handle = fopen($file, "r");
  if ($handle) {
    while (($line = fgets($handle)) !== false) {
        echo("<p>$line</p>");
    }
  } else {
    echo("error");
  } 
  fclose($handle);
}
//=========================================
$id  = $_GET['id'];

$s_day    = date('d');
$s_month  = date('m');
$s_year   = date('Y');


$value = readCurrentValue("time-$id.bess");
echo("<p>Enhet: <a href=\"bessConfig.php?action=id&id=$id\">$id</a>    $value</p>");
$value1 = readCurrentValue("pow-$id.bess");
$file4 = 'kwh-'.$id.'-'.$s_year.'-'.$s_month.'-'.$s_day.".bess"; 
$value2 = readCurrentValue($file4);
$value2 = $value2/1000;
echo("<h1>$value1 $value2 kWh</h1>");
showFileContent("graph-$id.bess");
showFileContent("consumer-$id.bess");

?>
